﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using UPos.Core;
using UPos.Core.Entity;
using UPos.Core.LogProvider;
using UPos.Core.RecordProvider;
using UPos.Core.SaleProvider;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            ShopInfo info = RecordSQLite.GetShop();
            EASSales s = new EASSales(new DateTime(2013, 6, 4), info, new RecordSQLite());

            if (s.NeedUp)
            {
                var NeedUps = s.GetNeedUp();
                var uped = new List<Sale>();
                Services serv = new Services();
                string mess;
                foreach (var item in NeedUps)
                {
                    if (serv.CallWebService(item, info, out mess))
                    {
                        uped.Add(item);
                    }
                }
                s.Recorder.SaveUnUp(uped, DateTime.Now);
            }
            var count = s.Recorder.GetUpedCount();
            Assert.IsTrue(count > 0);
        }

        [TestMethod]
        public void TestMethod2()
        {
            ShopInfo info = RecordSQLite.GetShop();
            PosSales s = new PosSales(new DateTime(2013, 5, 20), info, new RecordSQLite());

            if (s.NeedUp)
            {
                var NeedUps = s.GetNeedUp();
                List<Sale> uped = new List<Sale>();

                string mess;
                Services serv = new Services();
                foreach (var item in NeedUps)
                {
                    if (serv.CallWebService(item, info, out mess))
                        uped.Add(item);
                }

                s.Recorder.SaveUnUp(uped, DateTime.Now);
            }

            var count = s.Recorder.GetUpedCount();
            Assert.IsTrue(count > 0);
        }

        [TestMethod]
        public void TestMethod3()
        {
            var i = RecordSQLite.GetShop(1);
            EASSales s = new EASSales(DateTime.Now, i, new RecordSQLite());
            var l = s.GetNeedUp();
            Services serv = new Services();
            string mess;
            Sale sale = l[1];
            var result = serv.CallWebService(sale, i, out mess);
            s.Recorder.SaveUnUp(new List<Sale> { sale }, DateTime.Now);
            Assert.IsTrue(result);
        }

        [TestMethod]
        public void TestMethod4()
        {
            Sale item = new Sale
            {
                FID = "OT-LP-1",
                BizDate = DateTime.Now,
                MachineNo = "01",
                BillNumber = "OT-LP-1",
                CreaterNumber = "T-G",
                CreaterName = "T-G",
                Amount = 1,
                Paymentmoney = 100
            };

            string mess;
            Services serv = new Services();
            Assert.IsTrue(
                serv.CallWebService(item, RecordSQLite.GetShop(2), out mess));
        }

        [TestMethod]
        public void TestMethod5()
        {
            ShopInfo info = RecordSQLite.GetShop();
            EASSales s = new EASSales(new DateTime(2013, 6, 4), info, new RecordSQLite());
            s.Recorder.SaveUnUp(s.GetNeedUp(), DateTime.Now);
        }
    }
}
